// 导入账号登录API
import { userAccountLogin } from '@/api/user.js'
// 用户状态
export default {
  namespaced: true,
  state: () => ({
    profile: {
      id: '',
      account: '',
      nickname: '',
      avatar: '',
      token: '',
      mobile: ''
    }
  }),
  // 唯一能改变state的数据
  mutations: {
    setUser (state, payload) {
      state.profile = payload
    },
    // 清空用户数据
    clearUserInfo (state) {
      // 1.vuex 2.ls
      state.profile = {}
    }
  },
  // 异步操作
  actions: {
    async asyncSetUser (ctx, payload) {
      const res = await userAccountLogin(payload)
      ctx.commit('setUser', res.result)
    }
  }
}
